/*
 * @Author: LuZeng
 * @Date: 2022-08-29 14:05:42
 * @LastEditTime: 2022-09-01 15:52:39
 * @LastEditors: LuZeng
 * @Description: 小白本白，写的不好多多包涵！！！
 * @FilePath: \jsd:\rjiananzhuang\WEB\WEB workspace\lot-music\src\store\search.js
 * 别乱动！
 */
export default {
  namespaced: true,
  actions: {
    updateSearch(context, value) {
      let repeat = false;
      context.state.searchHistory.forEach((item) => {
        if (item == value) repeat = true;
      });
      context.commit("updateSearchWord", value);
      if (!repeat) {
        context.commit("updateSearchHistory", value);
      }
    },
    clearHistory(context) {
      context.state.searchHistory = [];
    },
  },
  mutations: {
    updateSearchWord(state, value) {
      state.searchWord = value;
    },
    updateSearchHistory(state, value) {
      state.searchHistory.unshift(value);
    },
  },
  state: {
    searchWord: "",
    searchHistory: [],
  },
};
